<% questionnaire.questions.includes([:questionnaire]).each do |question| %>
  <details class="meeting-polls__question meeting-polls__question--admin open" data-question="<%= question.id %>" <%= "open" if open_question == question.id %>>
    <summary>
      <span><%= t(".question") %></span>
      <span><%= t(question.status, scope: "decidim.meetings.polls.questions.index_admin.statuses") %></span>
    </summary>

    <%= form_tag(meeting_polls_question_path(meeting, question), method: :patch, remote: true) do %>
      <p class="h3"><%= translated_attribute(question.body) %></p>

      <% if question.unpublished? %>
        <%= link_to(
          t(".edit"),
          Decidim::EngineRouter.admin_proxy(meeting.component).edit_meeting_poll_path(meeting),
          class: "button button__xs button__secondary mr-auto mt-2",
          target: "_blank",
          rel: "noopener noreferrer"
        ) %>
      <% end %>

      <div>
        <div class="meeting-polls__admin-action meeting-polls__admin-action-question">
          <div class="h4"><%= t(".question") %><%= " · " + t(".sent") if question.published? %></div>

          <% if question.unpublished? %>
            <button class="button button__sm button__secondary"><%= t(".send") %></button>
          <% else %>
            <div><%= pluralize(question.responses_count, t(".received_response"), t(".received_responses")) %></div>
          <% end %>
        </div>

        <div class="meeting-polls__admin-action meeting-polls__admin-action-results">
          <div class="h4"><%= t(".results") %></div>

          <button class="button button__sm button__secondary" <%= question.published? ? "" : "disabled" %>><%= question.closed? ? t(".sent") : t(".send") %></button>

          <div>
            <% unless question.unpublished? %>
              <%= cell "decidim/meetings/question_responses", question %>
            <% end %>
          </div>
        </div>
      </div>
    <% end %>
  </details>
<% end %>
